@extends('admin.frame_layout')
<?php $top_selected = "会员管理";$page_menu = "会员属性添加" ?>

@section('content')
    <div class="formbody">
        <div class="formtitle"><span>会员属性编辑</span></div>
        <form action="{{route('admin.user_info.save',['id'=>(isset($attr)?$attr->id:0)])}}" method="post"
              id="admin">
            {!! csrf_field() !!}
            <ul class="forminfo">

                {!! inputText("名称","name","text",
                   isset($attr)?$attr->name:'',
                    "长度最好不超过20个字符！") !!}

                {{--@if(isset($attr))--}}
                    <input type="hidden" value="{{isset($attr)?$attr->mark:''}}" name="mark" id="mark">
                {{--@else--}}
                {{--<li>--}}
                    {{--<label class="lable">标识</label>--}}
                    {{--<input id="mark" name="mark" type="text"--}}
                           {{--class="dfinput" />--}}
                    {{--<i>全局唯一标示（系统自动为你添加前缀"attr_"）</i>--}}
                {{--</li>--}}
                {{--@endif--}}
                @if(isset($attr))
                <?php $flag = \App\Models\MUserAttr::getUnArray($attr->flag) ?>
                @endif
                <li>
                    <label class="lable" style="margin-top:-7px;">属性权限</label>
                    <input type="checkbox" value="1" name="reg" id="reg">&nbsp;注册&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="checkbox" value="1" name="withdraw" id="withdraw">&nbsp;提现&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="checkbox" value="1" name="transfer" id="transfer">&nbsp;转账&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="checkbox" value="1" name="accept_addr" id="accept_addr">&nbsp;收货地址&nbsp;&nbsp;&nbsp;&nbsp;
                    <i></i>
                </li>
                @if(isset($attr))
                   <?php $rule = \App\Models\MUserAttr::getUnArray($attr->rule)?>

                @endif

                @if(isset($attr))
                <?php $msg = \App\Models\MUserAttr::getUnArray($attr->msg)?>
                @endif

                <li><label class="lable">&nbsp;</label>
                    <input type="submit" class="btn" value="确认保存"/>
                </li>
            </ul>
        </form>
    </div>
@endsection

@section('footer')
    <script type="text/javascript">
        $("#admin").validate({
            rules: {
                name: {
                    required: true,
                    maxlength: 20
                },
                mark: {
                    required: true,
                    maxlength: 10
                }
            }, errorPlacement: function (error, element) {
                $(element).closest("form").find("i[for='" + element.attr("id") + "']").html(error);
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location = "{{route('admin.info')}}";
                            }, 2000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });
    </script>
    <script type="text/javascript">
      @if(isset($flag))
       var attr =[];
       @foreach($flag as $i=>$v)
           attr ['{{$i}}'] = '{{$v}}';
       @endforeach

        for(var key in attr){
            if (key == 'reg' && attr[key] == 1) {
                $('#reg').attr('checked',true);
            } else if (key == 'withdraw' && attr[key] == 1) {
                $('#withdraw').attr('checked',true);
            } else if (key == 'transfer' && attr[key] == 1) {
                $('#transfer').attr('checked',true);
            } else if (key == 'accept_addr' && attr[key] == 1) {
                $('#accept_addr').attr('checked',true);
            }
        }
        @endif
    </script>

@endsection
